package com.asiainfo.eom.service.impl;

import com.asiainfo.eom.entity.AdPlan;
import com.asiainfo.eom.mapper.AdPlanMapper;
import com.asiainfo.eom.service.IAdPlanService;
import com.asiainfo.eom.vo.AdPlanGetRequest;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class IAdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> implements IAdPlanService {
    @Override
    public AdPlan findByIdAndUserId(Long id, Long userId) {
        LambdaQueryWrapper<AdPlan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AdPlan::getId, id);
        queryWrapper.eq(AdPlan::getUserId, userId);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<AdPlan> findAllByIdInAndUserId(List<Long> ids, Long userId) {
        LambdaQueryWrapper<AdPlan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(AdPlan::getId, ids);
        queryWrapper.eq(AdPlan::getUserId, userId);
        return this.list(queryWrapper);
    }

    @Override
    public AdPlan findByUserIdAndPlanName(Long userId, String planName) {
        LambdaQueryWrapper<AdPlan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AdPlan::getUserId, userId);
        queryWrapper.eq(AdPlan::getPlanName, planName);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<AdPlan> findAllByPlanStatus(Integer status) {
        LambdaQueryWrapper<AdPlan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AdPlan::getPlanStatus, status);
        return this.list(queryWrapper);
    }

    @Override
    public AdPlanResponse createAdPlan(AdPlanRequest request) throws AdException {
        return null;
    }

    @Override
    public List<AdPlan> getAdPlanByIds(AdPlanGetRequest request) throws AdException {
        return Collections.emptyList();
    }

    @Override
    public AdPlanResponse updateAdPlan(AdPlanRequest request) throws AdException {
        return null;
    }

    @Override
    public void deleteAdPlan(AdPlanRequest request) throws AdException {

    }
}
